package kr.pe.mkseo.data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class AllAccounts {
	
	private Map<Category, List<Account>> map_;
	
	public AllAccounts() {
		map_ = Maps.newHashMap();
	}

	public void Add(Category category, Account account) {
		List<Account> accnts = map_.get(category);
		if (accnts == null) {
			accnts = Lists.newArrayList();
		}
		accnts.add(account);
		map_.put(category, accnts);
	}

	public List<Account> Get(Category c) {
		return map_.get(c);
	}
	
	public BigDecimal GetAccountSum(Category c) {
		List<Account> accnts = map_.get(c);
		BigDecimal sum = BigDecimal.ZERO;
		for (Account a: accnts) {
			sum = sum.add(a.GetLastBalanceRecord().GetAmount());
		}
		return sum;
	}
}
